#include "scene.h"

void Scene::cleanup()
{
	for (Drawable& d : ui_layer.drawables)
		if (d.render_data.owns_texture && d.render_data.texture != nullptr)
			SDL_DestroyTexture(d.render_data.texture);

	for (Button& b : ui_layer.buttons)
		if (b.render_data.owns_texture && b.render_data.texture != nullptr)
			SDL_DestroyTexture(b.render_data.texture);
}

SceneTypes Scene::get_scene_type()
{
	return type;
}

static bool empty_rect(SDL_Rect s) {
	return (s.x == 0 && s.y == 0 && s.w == 0 && s.h == 0);
}


Drawable& Scene::register_drawable(SDL_Texture *texture)
{
	Drawable d = Drawable(RenderData(texture, true));
	ui_layer.drawables.push_back(d);
	return ui_layer.drawables.back();
}

Button& Scene::register_button(SDL_Texture *texture, std::function<void()> callback)
{
	Button b = Button(RenderData(texture, true), callback);
	ui_layer.buttons.push_back(b);
	return ui_layer.buttons.back();
}

std::vector<Drawable>& Scene::get_drawables()
{
	return ui_layer.drawables;
}

std::vector<Button>& Scene::get_buttons()
{
	return ui_layer.buttons;
}